#include "Singularity.h"

Singularity::Singularity(float m, float r, float g)
{
	magnitude = m;
	setMass(m);
	effectiveRadius = r;
	effectiveRadiusSquared = r*r;
	gravConst = g;
	active = false;
	global = false;
}

void Singularity::affect(Entity *entity)
{
	Vec2d disp = this->pos - entity->pos;
	float r2 = disp*disp;
	if ((global || r2 < effectiveRadiusSquared) && r2 != 0.0f)
		entity->accel = entity->accel + disp.normalize() * ((gravConst * magnitude) / r2);
}

float Singularity::getEffectiveRadius()
{
	return effectiveRadius;
}

void Singularity::setEffectiveRadius(float r)
{
	this->effectiveRadius = r;
	this->effectiveRadiusSquared = r * r;
}